/* Copyright (c) 2008, dZettaApart.
   Licensed under the BSD License.
   See COPYING for details. */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/function.hpp>

#include "memcacheasio.h"
#include "memcacheasio_request.h"

using namespace memcacheasio;

void _callback_get ( Request::Ptr ticket )
{ 
	if ( ticket->responseStatus() )
	{
		std::cout << "Response status : ok" << std::endl;
	}
	else
	{
		std::cout << "Response status : bad" << std::endl;
	}
	std::cout << "Have an answer: ";
	std::cout << ticket->response() << std::endl;
}

int main ( /*int argc, char *argv[]*/ )
{
	try
	{
		printf ( "Hello, world!\n" );

        std::string host = "localhost";
//		std::string host = "127.0.0.1";
        std::string port = "11211";

//		boost::shared_ptr<Memcacheasio> memc ( new Memcacheasio() );
        Memcacheasio memc;

		memc.init ( host, port );

		memc.execute ( boost::shared_ptr<Request> ( new Request ( Request::COMMAND_GET, "hello_world", "" ) ), boost::bind ( &_callback_get, _1 ) );

		std::string	value ( "HELLO_HELLO" );
		memc.execute ( boost::shared_ptr<Request> ( new Request ( Request::COMMAND_SET, "hello_world", value ) ), boost::bind ( &_callback_get, _1 ) );

		memc.execute ( boost::shared_ptr<Request> ( new Request ( Request::COMMAND_GET, "hello_world", "" ) ), boost::bind ( &_callback_get, _1 )  );

		memc.execute ( boost::shared_ptr<Request> ( new Request ( Request::COMMAND_DELETE, "hello_world", "" ) ), boost::bind ( &_callback_get, _1 ) );

		sleep ( 10 );

	}
	catch ( std::exception& e )
	{
        std::cout << "Exception :" << e.what() << std::endl;
	}

	return EXIT_SUCCESS;
}
